package com.example.seckill.Controller;

import com.example.seckill.Exception.ErrorEnum;
import com.example.seckill.Exception.GlobalException;
import com.example.seckill.VO.BuildingVO;
import com.example.seckill.common.CommonResult;
import com.example.seckill.mapper.BuildingMapper;
import com.example.seckill.mapper.FacilityMapper;
import com.example.seckill.pojo.Facility;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/facility")
public class FacilityController {

    @Autowired
    BuildingMapper buildingMapper;

    @Autowired
    FacilityMapper facilityMapper;

    @PostMapping("getFacilityByBID")
    CommonResult<List<Facility>>GetFacilityByBID(@RequestBody BuildingVO building){
        Integer bid=building.getBuilding_id();
        BuildingVO res=buildingMapper.selectByBuildingID(bid);
        if(res==null) throw new GlobalException(ErrorEnum.NO_BUILDING_FOUND);
        return CommonResult.success(facilityMapper.getFacilityByBID(bid));
    }
}
